import service from '@/libs/http'

// 获取所有图片
export const getHistoryImages = () => {
  return service.get('/api/uploadimages')
}

// 删除单张图片
export const deleteImage = (index) => {
  return service.get(`/api/del?index=${index}`);
}

// 局部重绘接口
export const inpaintImage = (maskImage) => {
  return service.post('/api/uploadmask', maskImage)
}

export const getDownloadedImages = () => {
  return service.get('/api/user/downloaded-images')
}

export const downloadImage = (imageId) => {
  return service.post('/api/image/download', { imageId })
}

export const deleteDownloadRecord = (id) => {
  return service.delete(`/api/download/${id}`)
}

// 生成图片接口
export const getEncodedImages = ({desc = 'wu', style = '图生图', width = 1920, height = 1080, img = 'image'}) => {
  return service.post(`/api/g?prompt=${desc}&style=${style}&width=${width}&height=${height}&img=${img}`)
}

// 登录接口
export const login = (data) => {
  const formData = new FormData()
  formData.append('username', data.username)
  formData.append('password', data.password)
  return service.post('/api/login', formData)
}

// 注册接口
export const register = (data) => {
  console.log(data)
  return service.post('/api/register', data)
}

// 修改密码
export const changePassword = (data) => {
  return service.post("/api/chguserinfo", data);
};

// 获取单个用户信息
export const getUserInfo = () => {
  return service.get("/api/tokenuser");
};
